#import <UIKit/UIKit.h>
#import "CTSuperPlayer.h"
#import "CTSuperPlayerModel.h"
#import "CTSuperPlayerViewConfig.h"
#import "SPVideoFrameDescription.h"
@class CTSuperPlayerControlView;
@class CTSuperPlayerView;
@class TXImageSprite;

@class TXVodPlayer;
@class TXLivePlayer;
@protocol CTSuperPlayerDelegate;
@protocol CTSuperPlayerVodDelegate;
@protocol CTSuperPlayerLiveDelegate;

/// 播放器的状态
typedef NS_ENUM (NSInteger, CTSuperPlayerState) {
    StateFailed,     // 播放失败
    StateBuffering,  // 缓冲中
    StatePlaying,    // 播放中
    StateStopped,    // 停止播放
    StatePause,      // 暂停播放
};

/// 播放器布局样式
typedef NS_ENUM (NSInteger, CTSuperPlayerLayoutStyle) {
    CTSuperPlayerLayoutStyleCompact, ///< 精简模式
    CTSuperPlayerLayoutStyleFullScreen ///< 全屏模式
};

/// 视频控件旋转方式
typedef NS_ENUM (NSInteger, CTPlayerRotateOption) {
    CTPlayerRotateOption_Transform, // 旋转变换View
    CTPlayerRotateOption_RotateScreen, // 强制旋转屏幕
//    CTPlayerRotateOption_Custom, // 外部处理
};

#pragma mark - —————————————— CTSuperPlayerView ————————————

/// 播放器视图
@interface CTSuperPlayerView : UIView

/** 设置代理 */
@property (nonatomic, weak) id<CTSuperPlayerDelegate> delegate;
@property (nonatomic, weak) id<CTSuperPlayerVodDelegate> vodDelegate;
@property (nonatomic, weak) id<CTSuperPlayerLiveDelegate> liveDelegate;

/// 布局样式
@property (nonatomic, assign) CTSuperPlayerLayoutStyle layoutStyle;
/// 全屏旋转方式
@property (nonatomic, assign) CTPlayerRotateOption rotateOption; // 默认为 CTPlayerRotateOption_Transform

/// 设置播放器的父view。播放过程中调用可实现播放窗口转移
@property (nonatomic, weak) UIView *fatherView;
/// 播放器的状态
@property (nonatomic, assign) CTSuperPlayerState state;
/// 是否全屏
@property (nonatomic, assign, setter = setFullScreen:) BOOL isFullScreen;
/// 是否锁定旋转
@property (nonatomic, assign) BOOL isLockScreen;
/// 是否是直播流
@property (readonly) BOOL isLive;
/// 超级播放器控制层
@property (nonatomic) CTSuperPlayerControlView *controlView;
/// 是否允许竖屏手势
@property (nonatomic, assign) BOOL disableGesture;
/// 是否禁用所有控件
@property (nonatomic, assign) BOOL disableAllControlView;
/// 精简模式时隐藏返回按钮
@property (nonatomic, assign) BOOL hideBackButtonForCompactStyle;
/// 是否在手势中
@property (readonly)  BOOL isDragging;
/// 是否加载成功
@property (readonly)  BOOL isLoaded;
/// 设置封面图片
@property (nonatomic) UIImageView *coverImageView;
/// 重播按钮
@property (nonatomic, strong) UIButton *repeatBtn;
/// 全屏退出
@property (nonatomic, strong) UIButton *fullScreenBackBtn;
/// 是否自动播放（在playWithModel前设置)
@property BOOL autoPlay;
/// 视频总时长
@property (nonatomic) CGFloat playDuration;
/// 原始视频总时长，主要用于试看场景下显示总时长
@property (nonatomic) NSTimeInterval originalDuration;
/// 视频当前播放时间
@property (nonatomic) CGFloat playCurrentTime;
/// 起始播放时间，用于从上次位置开播
@property CGFloat startTime;
/// 播放的视频Model
@property (readonly) CTSuperPlayerModel *playerModel;
/// 播放器配置
@property CTSuperPlayerViewConfig *playerConfig;
/// 循环播放
@property (nonatomic, assign) BOOL loop;
/// 视频雪碧图
@property TXImageSprite *imageSprite;
/// 打点信息
@property NSArray<SPVideoFrameDescription *> *keyFrameDescList;
/// 播放model
- (void)playWithModel:(CTSuperPlayerModel *)playerModel;

- (void)resetPlayer; // 重置player
- (void)resume; // 播放
- (void)pause; // 暂停,  isLoaded == NO 时暂停无效

- (void)ct_stopPlay;
- (void)ct_removeVideoWidget;
- (void)ct_setupVideoWidget:(UIView *)view insertIndex:(unsigned int)idx;
- (CGSize)ct_videoSize; // 仅对点播有效
- (TXVodPlayer *)ct_getVodPlayer;
- (TXLivePlayer *)ct_getLivePlayer;

/// 从xx秒开始播放视频跳转
/// @param dragedSeconds 视频跳转的秒数
- (void)seekToTime:(NSInteger)dragedSeconds;

@end

#pragma mark - —————————————— CTSuperPlayerDelegate ————————————

@protocol CTSuperPlayerDelegate <NSObject>

@optional
/// 返回事件
- (void)superPlayerBackAction:(CTSuperPlayerView *)player;
/// 全屏改变通知
- (void)superPlayerFullScreenChanged:(CTSuperPlayerView *)player;
/// 播放开始通知
- (void)superPlayerDidStart:(CTSuperPlayerView *)player;
/// 播放结束通知
- (void)superPlayerDidEnd:(CTSuperPlayerView *)player;
/// 播放错误通知
- (void)superPlayerDidError:(CTSuperPlayerView *)player errorCode:(NSInteger)errorCode errorMessage:(NSString *)errorMessage;
/// 设置控制器是否允许旋转
- (void)superPlayerShouldRotate:(CTSuperPlayerView *)player canRotate:(BOOL)canRotate;

///// 切换全屏状态处理（外部）
//- (void)superPlayerShouldChangeFullScreen:(CTSuperPlayerView *)player fullScreen:(BOOL)isFullScreen;

@end

#pragma mark - —————————————— CTSuperPlayerVodDelegate ————————————

@protocol CTSuperPlayerVodDelegate <NSObject>

@optional

// 点播事件通知
- (void)onPlayEvent:(TXVodPlayer *)player event:(int)eventId withParam:(NSDictionary *)param playerView:(CTSuperPlayerView *)playerView;

// 网络状态通知
- (void)onNetStatus:(TXVodPlayer *)player withParam:(NSDictionary *)param playerView:(CTSuperPlayerView *)playerView;

@end

#pragma mark - —————————————— CTSuperPlayerLiveDelegate ————————————

@protocol CTSuperPlayerLiveDelegate <NSObject>

@optional

// 直播事件通知
- (void)onPlayEvent:(int)eventId withParam:(NSDictionary *)param playerView:(CTSuperPlayerView *)playerView;
// 网络状态通知
- (void)onNetStatus:(NSDictionary *)param playerView:(CTSuperPlayerView *)playerView;

@end
